import { createStore } from "vuex";
// import createPersistedstate from 'vuex-persistedstate'
import { createOrder } from "@/api/orderList";
import { userInfo } from "@/api/home"

export default createStore({
	state: {
		// 后期去actions里面发送异步请求，更改商城的数据
		product: {
			name: "锦鲤算力机-K1",
			pic: "/static/images/Shop/Shop_first_bg.png",
			price: 2000,
			each: 1234, // 已售多少件
			OriginalPrice: 3999,
			RemainingTaiwan: 123,
			freight: 100,
			quantity: 1,
		},
		showBottom: false,
		// 保存用户输入的支付密码
		KeyValue: "",
		// 保存选择方式的标题
		title: "寄回",
		// 创建时间
		createTime: "",
		// 支付时间
		paymentTime: "",
		// 设备托管记录
		equipmentList: [
			{
				time: "10月24日",
				children: [
					{ cTime: "00:33", type: "托管", num: "-1" },
					{ cTime: "00:33", type: "托管", num: "-1" },
					{ cTime: "00:33", type: "购买", num: "+9" },
				],
			},
			{
				time: "10月21日",
				children: [
					{ cTime: "00:33", type: "购买", num: "+5" },
					{ cTime: "00:33", type: "购买", num: "+10" },
				],
			},
			{
				time: "10月12日",
				children: [
					{ cTime: "00:33", type: "托管", num: "-1" },
					{ cTime: "00:33", type: "托管", num: "-1" },
					{ cTime: "00:33", type: "购买", num: "+9" },
				],
			},
			{
				time: "10月11日",
				children: [
					{ cTime: "00:33", type: "购买", num: "+5" },
					{ cTime: "00:33", type: "购买", num: "+10" },
				],
			},
			{
				time: "10月10日",
				children: [
					{ cTime: "00:33", type: "购买", num: "5" },
					{ cTime: "00:33", type: "购买", num: "10" },
				],
			},
		],
		// 安全密码
		securityCodeValue: '123456',
		// 判断注册还是忘记密码
		psdSign: "注册",
		// 注册的变量
		sign: {
			// 判断是否时邮箱发送还是电话号码发送
			number: "号码注册",
			// 邮箱号
			Email: "",
			// 手机号
			phone: "",
			// 区号
			areacode: "",
			// 邀请码
			inviteCode: "",
			// 密码
			password: "",
			// 支付密码
			payPassword: "",
			// 注册类型
			sourceType: 1,
			// 类型
			type: 2,
			// 验证码
			code: "",
		},
		// 用户信息
		userInfo: []
	},
	mutations: {
		EditShowBottom(state, value : boolean) {
			state.showBottom = value;
		},
		// 保存选择方式的回调
		SaveSelectionFn(state, value : string) {
			state.title = value;
			// console.log(state.title)
		},
		// 替换数字数据
		replaceDataFn(state, value : number) {
			state.product.quantity = value;
			console.log(state.product);
		},
		// 保存创建订单的时间
		saveTimeFn(state, value : string) {
			state.createTime = value;
			console.log(state.createTime);
		},
		// 保存支付时间
		savePaymentTimeFn(state, value : string) {
			state.paymentTime = value;
			console.log(state.paymentTime);
		},
		// 保存商品的数据
		saveProduct(state, data : any) {
			state.product = data.data
			console.log(state.product)
		},
		// 操控注册中的邮箱/手机号的切换
		GATDATA(state) {
			//将数据存到satte中
			state.sign.number =
				state.sign.number === "邮箱注册" ? "号码注册" : "邮箱注册";
			console.log(state.sign.number);
		},
	},
	actions: {
		getOrderData: async (context, data) => {
			// console.log(data)
			const result = await createOrder(data); // 拿到数据了
			console.log(result,'aaaa');
			context.commit('saveProduct', result)
		},
		getUserInfo: async (context) => {
			const res = await userInfo()
			// context.state.userInfo = result
			console.log(res,context.state.userInfo)
		}
	},
	getters: {
		GetShowBottom: (state) => {
			return state.showBottom;
		},
	},
	modules: {},
	plugins: [],
});